
OBJS := $(COBJS)
DETS := $(patsubst %.o, %.det, $(OBJS))

MYOBJS := $(addprefix $(COMP_BUILD_DIR)/$(COMPONENT)/, $(OBJS))
MYOBJS += $(addprefix $(COMP_BUILD_DIR)/$(COMPONENT)/, $(ASMOBJS))
MYDETS := $(addprefix $(COMP_BUILD_DIR)/$(COMPONENT)/, $(DETS))
MYLOGS := $(addsuffix .log, $(MYOBJS))

TARGET_DEP := $(COMP_BUILD_DIR)/$(COMPONENT)/$(COMPONENT).dep
TARGET_LIB := $(COMP_BUILD_DIR)/$(COMPONENT)/$(COMPONENT).tmp.o
MYLOGS += $(TARGET_LIB).log

vpath 
vpath %.c $(PWD)/$(COMPONENT)
vpath %.h $(PWD)/include $(PWD)/include/cnix
vpath %.o $(COMP_BUILD_DIR)/$(COMPONENT)
vpath %.det $(COMP_BUILD_DIR)/$(COMPONENT)

all: $(TARGET_LIB)

ifndef OVERRIDING
$(TARGET_LIB):	$(OBJS) $(ASMOBJS)
	@-rm -f $(TARGET_LIB).log
	@-cat $(COMP_BUILD_DIR)/$(COMPONENT)/*.log > $(TARGET_LIB).log
	@$(LD) $(LDFLAGS) -o $@ $(MYOBJS) >> $(TARGET_LIB).log
endif

%.o: %.c 
	@echo $@
	@$(CC) $(CFLAGS) -c $< -o $(COMP_BUILD_DIR)/$(COMPONENT)/$@ > $(COMP_BUILD_DIR)/$(COMPONENT)/$@.log
%.o: %.S
	@echo $@
	@$(CC) $(CFLAGS) -c $< -o $(COMP_BUILD_DIR)/$(COMPONENT)/$@ > $(COMP_BUILD_DIR)/$(COMPONENT)/$@.log

#%.d: %.c
#	rm -f $@ ; \
	$(CC) $(CFLAGS) -MM $< >$@.$$$$; \
	sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
	rm -f $@.$$$$

%.det: %.c
	@rm -f $(COMP_BUILD_DIR)/$(COMPONENT)/$@ ; \
	$(CC) $(CFLAGS) -MM $< >$(COMP_BUILD_DIR)/$(COMPONENT)/$@.$$$$; \
	sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $(COMP_BUILD_DIR)/$(COMPONENT)/$@.$$$$ > $(COMP_BUILD_DIR)/$(COMPONENT)/$@; \
	rm -f $(COMP_BUILD_DIR)/$(COMPONENT)/$@.$$$$

-include $(TARGET_DEP)

dep: $(TARGET_DEP)

$(TARGET_DEP): $(DETS)
	@if [ -f $(TARGET_DEP) ]; then rm -f $(TARGET_DEP); fi
	@cat $(COMP_BUILD_DIR)/$(COMPONENT)/*.det >> $(TARGET_DEP)

ifndef OVERRIDING
clean:
	@rm -f *.o .*.swp *~ .tmp.o *.dep $(MYOBJS) $(MYDETS) $(TARGET_DEP) $(TARGET_LIB) $(MYLOGS)
endif	
